package com.sogoodsoft.service.crm;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.sogoodsoft.dao.common.CommonHibernateDao;
import com.sogoodsoft.dao.crm.SmsDao;
import com.sogoodsoft.entity.crm.Sms;
import com.sogoodsoft.entity.crm.Smstask;
import com.sogoodsoft.service.common.AbstractService;
@Component
@Transactional
public class SmsService extends AbstractService<Sms, Long> {

	@Autowired
	private SmsDao dao;
	@Override
	public CommonHibernateDao<Sms, Long> getDao() {
		return dao;
	}
	
	/**
	 * 获取待发短信，每次50条
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Sms> getSmsList(){
		Criteria smsCriteria = dao.getSession().createCriteria(Sms.class);
		smsCriteria.add(Restrictions.lt("plantime", new Date()));
		smsCriteria.createCriteria("sendSatus").add(Restrictions.eq("code",  Smstask.SEND_STATUS_CODE.WAIT.getCODE()));
		smsCriteria.addOrder(Order.asc("plantime"));
		smsCriteria.setMaxResults(50);
		return smsCriteria.list();

	}
	

}
